package com.itany.corejava.code06_面向对象;

import java.util.Arrays;

/**
 * @author 石小俊
 * @date 2024年01月15日 9:54
 */
public class Test01_类的使用 {
    public static void main(String[] args) {
        Person person = new Person();
        // 通过对象名.属性名可以访问对应的属性
        person.name = "张三";
        person.age = 20;
        person.gender = "男";
        person.hobbies = new String[]{"吃饭", "睡觉", "打豆豆"};
        System.out.println(person.name);
        // 通过对象名.方法名访问对应方法
        person.eat();
        person.sleep();
        person.show();

        Person person2 = new Person();
        person2.name = "李四";
        person2.age = 18;
        person2.gender = "女";
        person2.hobbies = new String[]{"逛街", "购物"};
        System.out.println(person.name);
        System.out.println(person2.name);
        person2.eat();
        person2.sleep();
        person2.show();
    }
}

class Person {
    // 成员属性
    String name;
    int age;
    String gender;
    String[] hobbies;

    // 成员方法
    public void eat() {
        System.out.println(name + "饿了,想要吃饭");
    }

    public void sleep() {
        System.out.println(name + "困了,想要睡觉了");
    }

    public void show() {
        System.out.println("我叫" + name + ",我今年" + age + "岁,是一位" + gender + "士,我的兴趣爱好:" + Arrays.toString(hobbies));
    }

}
